package com.brianway.learning.java.multithread.synchronize.example16;

/**
 * Created by Brian on 2016/4/13.
 */

/**
 * P124
 * volatile非原子的特性
 */
public class Run16_volatile {
    public static void main(String[] args) {
        MyThread[] myThreads = new MyThread[100];
        for (int i = 0; i < 100; i++) {
            myThreads[i] = new MyThread();
        }
        for (int i = 0; i < 100; i++) {
            myThreads[i].start();
        }

    }
}

/*
addCount不加synchronized
输出：
count=200
count=200
count=300
count=400
count=500
count=600
count=700
count=800
count=900
count=1000
count=1100
count=1200
count=1300
count=1400
count=1500
count=1600
count=1700
count=1800
count=1900
count=2000
count=2100
count=2200
count=2300
count=2400
count=2500
count=2600
count=2700
count=2800
count=2900
count=3000
count=3100
count=3200
count=3300
count=3400
count=3500
count=3600
count=3700
count=3800
count=3900
count=4000
count=4100
count=4200
count=4300
count=4400
count=4500
count=9456
count=9456
count=9456
count=9456
count=9456
count=9456
count=9456
count=9456
count=9456
count=9456
count=9456
count=9456
count=9456
count=9456
count=9456
count=9556
count=9456
count=9656
count=9756
count=9756
count=9756
count=9856
count=9456
count=9456
count=9456
count=9456
count=9856
count=9856
count=9856
count=9856
count=9856
count=9856
count=9856
count=9856
count=9856
count=9856
count=9856
count=9856
count=9856
count=9756
count=9756
count=9656
count=9556
count=9556
count=9956
count=9856
count=9856
count=9856
count=9856
count=9856
count=9856
count=9856
count=9856
count=9856
count=9856


-----------------------------
addCount()加synchronized
输出：
count=100
count=200
count=300
count=400
count=500
count=600
count=700
count=800
count=900
count=1000
count=1100
count=1200
count=1300
count=1400
count=1500
count=1600
count=1700
count=1800
count=1900
count=2000
count=2100
count=2200
count=2300
count=2400
count=2500
count=2600
count=2700
count=2800
count=2900
count=3000
count=3100
count=3200
count=3300
count=3400
count=3500
count=3600
count=3700
count=3800
count=3900
count=4000
count=4100
count=4200
count=4300
count=4400
count=4500
count=4600
count=4700
count=4800
count=4900
count=5000
count=5100
count=5200
count=5300
count=5400
count=5500
count=5600
count=5700
count=5800
count=5900
count=6000
count=6100
count=6200
count=6300
count=6400
count=6500
count=6600
count=6700
count=6800
count=6900
count=7000
count=7100
count=7200
count=7300
count=7400
count=7500
count=7600
count=7700
count=7800
count=7900
count=8000
count=8100
count=8200
count=8300
count=8400
count=8500
count=8600
count=8700
count=8800
count=8900
count=9000
count=9100
count=9200
count=9300
count=9400
count=9500
count=9600
count=9700
count=9800
count=9900
count=10000
 */